////////////////////////////////////////////////////////////////////////////////////////////////////
/// Copyright (c) 2009 - 2010 RacoonStudios
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this
/// software and associated documentation files (the "Software"), to deal in the Software
/// without restriction, including without limitation the rights to use, copy, modify, merge,
/// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
/// to whom the Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all copies or
/// substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
/// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
/// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
/// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS IN THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once
#ifndef stack_h__
#define stack_h__

#include "core/types.h"
#include "helper/array.h"

namespace Helper
{
	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// \class	Stack
	///
	/// \brief	This Stack is just the same as you can find within the std.
	///			Nothing special about it so I can't imagine writing here.
	///
	/// \author	khaos
	/// \date	03.12.2009
	////////////////////////////////////////////////////////////////////////////////////////////////////
	template<class T>
	class Stack
	{
		public:

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	Stack()
			///
			/// \brief	Default constructor. 
			///
			/// \author	khaos
			/// \date	03.12.2009
			////////////////////////////////////////////////////////////////////////////////////////////////////
			Stack();

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	Stack(const T & element)
			///
			/// \brief	Constructor. 
			///
			/// \author	Khaos
			/// \date	02.01.2010
			///
			/// \param	[in]	element	The element we want to add.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			Stack(const T & element);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	Stack(const Stack<T> & rhs)
			///
			/// \brief	Constructor. 
			///
			/// \author	khaos
			/// \date	03.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			Stack(const Stack<T> & rhs);




			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void operator= (const Stack<T> & rhs)
			///
			/// \brief	Copy operator. 
			///
			/// \author	khaos
			/// \date	03.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void operator = (const Stack<T> & rhs);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	bool operator== (const Stack<T> & rhs) const
			///
			/// \brief	Equality operator. 
			///
			/// \author	khaos
			/// \date	03.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			///
			/// \return	True if both elements are equal, otherwise false.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			bool operator == (const Stack<T> & rhs) const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	bool operator!= (const Stack<T> & rhs) const
			///
			/// \brief	Inequality operator. 
			///
			/// \author	khaos
			/// \date	03.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			///
			/// \return	True if both objects are inequal, otherwise false.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			bool operator != (const Stack<T> & rhs) const;




			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	tSize Size() const
			///
			/// \brief	Returns the size of the stack. 
			///
			/// \author	khaos
			/// \date	03.12.2009
			////////////////////////////////////////////////////////////////////////////////////////////////////
			tSize Size() const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	bool Contains(const T & element) const
			///
			/// \brief	Determines if this collection contains a given object. 
			///
			/// \author	khaos
			/// \date	03.12.2009
			///
			/// \param	[in]	element	The const T & to test for containment. 
			///
			/// \return	True if the specified object is within the containment, otherwise false.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			bool Contains(const T & element) const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	bool IsEmpty() const
			///
			/// \brief	Determines if this containment is empty.
			///
			/// \author	khaos
			/// \date	03.12.2009
			///
			/// \return	True if this object is empty, otherwise false.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			bool IsEmpty() const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void Clear()
			///
			/// \brief	Clears the Stack.
			///
			/// \author	khaos
			/// \date	05.01.2010
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void Clear();





			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	T & Peek() const
			///
			/// \brief	Returns the top-of-stack object without removing it. 
			///
			/// \author	khaos
			/// \date	03.12.2009
			///
			/// \return	The current top-of-stack object. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			T & Peek() const;




			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void Push(const T & element)
			///
			/// \brief	Pushes an object onto this stack. 
			///
			/// \author	khaos
			/// \date	03.12.2009
			///
			/// \param	[in]	element	The element we want to put on the stack.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void Push(const T & element);




			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void Pop()
			///
			/// \brief	Removes and returns the top-of-stack object. 
			///
			/// \author	khaos
			/// \date	03.12.2009
			///
			/// \return	The previous top-of-stack object. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void Pop();

		protected:

			Array<T> m_elements;

		private:

	};





	///
	template<class T>
	inline Stack<T>::Stack()
	{

	}


	///
	template<class T>
	inline Stack<T>::Stack(const T &element)
	{
		this->m_elements.Add(element);
	}


	///
	template<class T>
	inline Stack<T>::Stack(const Helper::Stack<T> &rhs)
	{
		this->m_elements.AddArray(rhs.m_elements);
	}





	///
	template<class T>
	inline void Stack<T>::operator =(const Helper::Stack<T> &rhs)
	{
		
	}


	///
	template<class T>
	inline bool Stack<T>::operator ==(const Helper::Stack<T> &rhs) const
	{
		if(this->Size() <= 0)
			return false;

		for(tIndex i = 0; i < this->Size(); i++)
		{
			if(!(this->m_elements[i] == rhs.m_elements[i]))
				return false;
		}

		return true;
	}


	///
	template<class T>
	inline bool Stack<T>::operator !=(const Helper::Stack<T> &rhs) const
	{
		return !(*this == rhs);
	}





	///
	template<class T>
	inline tSize Stack<T>::Size() const
	{
		return this->m_elements.Size();
	}


	///
	template<class T>
	inline bool Stack<T>::Contains(const T &element) const
	{
		return this->m_elements.Contains(element);
	}


	///
	template<class T>
	inline bool Stack<T>::IsEmpty() const
	{
		return this->m_elements.IsEmpty();
	}





	///
	template<class T>
	inline T & Stack<T>::Peek() const 
	{
		return this->m_elements[this->m_elements.Size()];
	}


	///
	template<class T>
	inline void Stack<T>::Push(const T &element)
	{
		this->m_elements.Add(element);
	}


	///
	template<class T>
	inline void Stack<T>::Pop()
	{
		this->m_elements.EraseIndex(this->Size() - 1);
	}

}